package com.nidu.demo.permission;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.nidu.demo.menu.dto.MenuTreeCO;
import com.nidu.demo.permission.command.PermissionUpdateCmdExe;
import com.nidu.demo.permission.query.PermissionListQryExe;
import com.nidu.demo.permission.query.PermissionSingleQryExe;
import com.nidu.demo.permission.api.SysPermissionService;
import com.nidu.demo.role.dto.RoleMenuAssignCmd;
import com.nidu.demo.user.dto.UserPermissionInfoCO;
import com.nidu.demo.user.dto.UserRoleAssignCmd;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
@RequiredArgsConstructor
public class SysPermissionServiceImpl implements SysPermissionService {

    private final PermissionSingleQryExe singleQryExe;

    private final PermissionListQryExe listQryExe;

    private final PermissionUpdateCmdExe updateCmdExe;

    @Override
    public SingleResponse<UserPermissionInfoCO> getPermissionInfo(Long loginUserId) {
        return singleQryExe.getPermissionInfo(loginUserId);
    }

    @Override
    public MultiResponse<MenuTreeCO> getMenuInfo(Long loginUserId) {
        return singleQryExe.getAccessibleMenus(loginUserId);
    }

    @Override
    public SingleResponse<Boolean> hasAnyPermissions(Long userId, String... permissions) {
        return singleQryExe.hasAnyPermissions(userId, permissions);
    }

    @Override
    public SingleResponse<Boolean> hasAnyRoles(Long userId, String... roles) {
        return singleQryExe.hasAnyRoles(userId, roles);
    }

    @Override
    public MultiResponse<Long> getUserRoles(Long userId) {
        return listQryExe.getUserRoles(userId);
    }

    @Override
    public Response assignUserRole(UserRoleAssignCmd cmd) {
        return updateCmdExe.assignUserRole(cmd);
    }

    @Override
    public MultiResponse<Long> getRoleMenus(Long roleId) {
        return listQryExe.getRoleMenus(roleId);
    }

    @Override
    public Response assignRoleMenu(RoleMenuAssignCmd cmd) {
        return updateCmdExe.assignRoleMenu(cmd);
    }

}